package com.prathiba.tictactoe;

import java.util.HashMap;
import java.util.Map;

public class Game {
	UserPlay uplay1 = new UserPlay();
	UserPlay uplay2 = new UserPlay();

	Map<Integer, UserPlay> map = new HashMap<Integer, UserPlay>();
	{
		map.put(1, uplay1);
		map.put(2, uplay2);
	}

	public void addCoordinate(int userId, Coordinate coordinate) {

		map.get(userId).addCoordinate(coordinate);
	}

	public UserPlay getUser(int userId) {
		return map.get(userId);
	}

	public boolean doesListContainCoordinate(Coordinate c) {
		if (uplay1.getCoordinates().contains(c)
				|| uplay2.getCoordinates().contains(c)) {
			return true;
		}
		return false;
	}

	public boolean gameDraw() {
		boolean user1won = uplay1.gameWon();
		boolean user2won = uplay2.gameWon();

		int numuser1 = uplay1.getCoordinates().size();
		int numuser2 = uplay2.getCoordinates().size();

		if (numuser1 + numuser2 == 9 && !user1won && !user2won)
			return true;

		return false;

	}

	public boolean gameWon() {
		if (uplay1.gameWon() || uplay2.gameWon())
			return true;

		return false;
	}
}
